package com.ytq.secutiry.config.handler;

import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.authentication.AuthenticationFailureHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author yuantongqin
 * desc: 请求验证失败
 * 2020-09-30
 */
@Component
public class FailureHandlerRequest implements AuthenticationFailureHandler {
    @Override
    public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response, AuthenticationException exception) throws IOException, ServletException {

        // 失败之后
        System.out.println("处理请求失败");

        response.setCharacterEncoding("utf-8");
        response.getWriter().write("处理请求失败");
    }
}
